
/**
 * 时间戳转化为yyyy-MM-dd字符串
 * @param time
 * @returns {string}
 */
 export function dateFormat(time) {
    if (time === null) {
      return ''
    }
    const date = new Date(time)
    const year = date.getFullYear()
    const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    return year + '-' + month + '-' + day
  }

  /**
 * 时间戳转化为yyyy-MM-dd HH:mm:ss字符串
 * @param time
 * @returns {string}
 */
export function datetimeFormat(time) {
    if (time === null) {
      return ''
    }
    const date = new Date(time)
    const year = date.getFullYear()
    const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
    const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
    const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
  }
  
    /**
 * 时间戳转化为HH:mm:ss字符串
 * @param time
 * @returns {string}
 */
export function timeFormt(time){
  if(time === null) return ''
  const date = new Date(time)
  const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  return hours + ':' + minutes + ':' +seconds
}
